package com.k.kppcloud.gateway.service.impl;

import com.alibaba.cloud.nacos.discovery.NacosDiscoveryClient;
import com.alibaba.nacos.api.naming.NamingService;
import com.k.kppcloud.gateway.service.NacosService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NacosServiceImpl implements NacosService {
    @Autowired
    private DiscoveryClient discoveryClient;
    @Override
    public List<String> queryAllInstances() {
        List<String> services = discoveryClient.getServices();
        for(String service:services){
            System.out.println("service:"+service);
            List<ServiceInstance> instances = discoveryClient.getInstances(service);
            for(ServiceInstance instance:instances){
                System.out.println("instance:"+instance);
            }
        }
        return services;
    }
}
